package com.ruoyi.dynamic.service.impl;

import java.util.List;

import com.ruoyi.comment.domain.PwComment;
import com.ruoyi.comment.service.IPwCommentService;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.dynamic.mapper.PwDynamicMapper;
import com.ruoyi.dynamic.domain.PwDynamic;
import com.ruoyi.dynamic.service.IPwDynamicService;

import javax.annotation.Resource;

/**
 * 发现管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-07-29
 */
@Service
public class PwDynamicServiceImpl implements IPwDynamicService 
{
    @Autowired
    private PwDynamicMapper pwDynamicMapper;
    @Resource
    private IPwCommentService pwCommentService;

    /**
     * 查询发现管理
     * 
     * @param id 发现管理主键
     * @return 发现管理
     */
    @Override
    public PwDynamic selectPwDynamicById(Long id)
    {
        return pwDynamicMapper.selectPwDynamicById(id);
    }

    /**
     * 查询发现管理列表
     * 
     * @param pwDynamic 发现管理
     * @return 发现管理
     */
    @Override
    public List<PwDynamic> selectPwDynamicList(PwDynamic pwDynamic)
    {
        List<PwDynamic> pwDynamics = pwDynamicMapper.selectPwDynamicList(pwDynamic);
        pwDynamics.forEach(dynamic -> {
            PwComment pwComment = new PwComment();
            pwComment.setCommentId(dynamic.getId());
            pwComment.setType(PwComment.COMMENT_TYPE_DYNAMIC);
            List<PwComment> commentList = pwCommentService.selectPwCommentList(pwComment);
            dynamic.setCommentList(commentList);
        });
        return pwDynamics;
    }

    /**
     * 新增发现管理
     * 
     * @param pwDynamic 发现管理
     * @return 结果
     */
    @Override
    public int insertPwDynamic(PwDynamic pwDynamic)
    {
        pwDynamic.setCreateTime(DateUtils.getNowDate());
        return pwDynamicMapper.insertPwDynamic(pwDynamic);
    }

    /**
     * 修改发现管理
     * 
     * @param pwDynamic 发现管理
     * @return 结果
     */
    @Override
    public int updatePwDynamic(PwDynamic pwDynamic)
    {
        pwDynamic.setUpdateTime(DateUtils.getNowDate());
        return pwDynamicMapper.updatePwDynamic(pwDynamic);
    }

    /**
     * 批量删除发现管理
     * 
     * @param ids 需要删除的发现管理主键
     * @return 结果
     */
    @Override
    public int deletePwDynamicByIds(Long[] ids)
    {
        return pwDynamicMapper.deletePwDynamicByIds(ids);
    }

    /**
     * 删除发现管理信息
     * 
     * @param id 发现管理主键
     * @return 结果
     */
    @Override
    public int deletePwDynamicById(Long id)
    {
        return pwDynamicMapper.deletePwDynamicById(id);
    }
}
